package com.vercal.demoverticalviewpager;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.vercal.demoverticalviewpager.adapter.ContentFragmentAdapter;
import com.vercal.demoverticalviewpager.bean.modelData;
import com.vercal.demoverticalviewpager.fragment.ContentFragment;
import com.vercal.demoverticalviewpager.view.AoSmithTransformer;
import com.vercal.demoverticalviewpager.view.Util;
import com.vercal.demoverticalviewpager.view.VerticalViewPager;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    List<modelData> datas;

    private Button btn_moni;

    ContentFragmentAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        btn_moni.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                datas.clear();
                for(int j=0;j<6;j++){
                    modelData modelData=new modelData();
                    modelData.setModel_name("模式"+ Util.getGUID());
                    modelData.setRoom_name1("客厅"+j);
                    modelData.setRoom_name2("卧室"+j);
                    modelData.setRoom_name3("厨房"+j);
                    modelData.setValue1("PM2.5"+j);
                    modelData.setRoom_name3("甲醛"+j);
                    modelData.setRoom_name3("温度"+j);
                    datas.add(modelData);
                }
                adapter.notifyDataSetChanged();
            }

        });
    }

    private void initView(){
        btn_moni=findViewById(R.id.btn_moni);
        VerticalViewPager viewPager = (VerticalViewPager) findViewById(R.id.vertical_viewpager);
        viewPager.setPageTransformer(false, new AoSmithTransformer());
        //  viewPager.setPageTransformer(true, new StackTransformer());
        String title = "ContentFragment";
        List<Fragment> fragments=new ArrayList<>();
        datas=new ArrayList<>();
        for(int j=0;j<6;j++){
            modelData modelData=new modelData();
            modelData.setModel_name("模式"+j);
            modelData.setRoom_name1("客厅"+j);
            modelData.setRoom_name2("卧室"+j);
            modelData.setRoom_name3("厨房"+j);
            modelData.setValue1("PM2.5"+j);
            modelData.setRoom_name3("甲醛"+j);
            modelData.setRoom_name3("温度"+j);
            datas.add(modelData);
        }
        for(int i=0;i<datas.size();i++){
            ContentFragment contentFragment=new ContentFragment();
            fragments.add(contentFragment);
        }
        adapter=new ContentFragmentAdapter(getSupportFragmentManager(),fragments,datas);
        viewPager.setAdapter(adapter);
        //If you setting other scroll mode, the scrolled fade is shown from either side of display.
        viewPager.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
        adapter.notifyDataSetChanged();
    }

}